package com.houweishi.module.companydocument.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.module.companydocument.domain.BizCompanyDocument;
import com.houweishi.module.companydocument.service.IBizCompanyDocumentService;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.common.core.page.TableDataInfo;

/**
 * 文档管理Controller
 * 
 * @author houweishi
 * @date 2023-02-26
 */
@RestController
@RequestMapping("/module/companydocument")
public class BizCompanyDocumentController extends BaseController
{
    @Autowired
    private IBizCompanyDocumentService bizCompanyDocumentService;

    /**
     * 查询文档管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:companydocument:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCompanyDocument bizCompanyDocument)
    {
        startPage();
        List<BizCompanyDocument> list = bizCompanyDocumentService.selectBizCompanyDocumentList(bizCompanyDocument);
        return getDataTable(list);
    }

    /**
     * 导出文档管理列表
     */
    @PreAuthorize("@ss.hasPermi('module:companydocument:export')")
    @Log(title = "文档管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizCompanyDocument bizCompanyDocument)
    {
        List<BizCompanyDocument> list = bizCompanyDocumentService.selectBizCompanyDocumentList(bizCompanyDocument);
        ExcelUtil<BizCompanyDocument> util = new ExcelUtil<BizCompanyDocument>(BizCompanyDocument.class);
        util.exportExcel(response, list, "文档管理数据");
    }

    /**
     * 获取文档管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:companydocument:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizCompanyDocumentService.selectBizCompanyDocumentById(id));
    }

    /**
     * 新增文档管理
     */
    @PreAuthorize("@ss.hasPermi('module:companydocument:add')")
    @Log(title = "文档管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCompanyDocument bizCompanyDocument)
    {
        return toAjax(bizCompanyDocumentService.insertBizCompanyDocument(bizCompanyDocument));
    }

    /**
     * 修改文档管理
     */
    @PreAuthorize("@ss.hasPermi('module:companydocument:edit')")
    @Log(title = "文档管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCompanyDocument bizCompanyDocument)
    {
        return toAjax(bizCompanyDocumentService.updateBizCompanyDocument(bizCompanyDocument));
    }

    /**
     * 删除文档管理
     */
    @PreAuthorize("@ss.hasPermi('module:companydocument:remove')")
    @Log(title = "文档管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizCompanyDocumentService.deleteBizCompanyDocumentByIds(ids));
    }
}
